package com.dreambreeze.common.bean;

import com.dreambreeze.common.utils.ConstantKey;

/**
 * @description: 方法返回对象1
 * @auther: dream breeze
 * @date: 2019/07/22 20:12
 */
public class ResultBean {
    private int code;
    private String msg;
    private Object data;

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    @Override
    public String toString() {
        return "ServerResult{" + "code=" + code + ", msg='" + msg + '\'' + ", data=" + data + '}';
    }

    public ResultBean() {

    }

    public ResultBean(int code, String msg, Object data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public ResultBean(Object data) {
        this.code = ConstantKey.SUCCESS_CODE;
        this.msg = ConstantKey.SUCCESS_MSG;
        this.data = data;
    }

    public static ResultBean build(Integer code, String msg, Object data) {
        return new ResultBean(code, msg, data);
    }

    public static ResultBean build(Integer code, String msg) {
        return new ResultBean(code, msg, null);
    }

    public static ResultBean ok(Object data) {
        return new ResultBean(data);
    }

    public static ResultBean ok() {
        return new ResultBean(null);
    }

    public ResultBean(Integer code, String msg, Object data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static ResultBean getInstance() {
        return new ResultBean();
    }

    public static ResultBean noData() {
        return new ResultBean(ConstantKey.NODATA_CODE, ConstantKey.NODATA_MSG, null);
    }

    public static ResultBean errorParam(){
        return new ResultBean(ConstantKey.FAIL_CODE, ConstantKey.ERROR_PARAM, null);
    }

    public static ResultBean error(String msg){
        return new ResultBean(ConstantKey.FAIL_CODE, msg, null);
    }

    public static ResultBean defeated(){
        return new ResultBean(ConstantKey.FAIL_CODE, ConstantKey.FAIL_MSG, null);
    }
}
